<template>
  <div class="todo-operate">
    <span class="todo-count">{{ num }} task</span>
    <div class="todo-choose">
      <!-- 点击类型必须告诉父组件儿子点了哪个类型 -->
      <span class="todo-all btn" :class="{active: currentType === 'all'}" @click="changeType('all')">all</span>
      <span class="todo-active btn" :class="{active: currentType === 'active'}" @click="changeType('active')">active</span>
      <span class="todo-completed btn" :class="{active: currentType === 'completed'}" @click="changeType('completed')">completed</span>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 记录当前点的类型
      currentType: "all",
    };
  },
  methods: {
    changeType(type) {
      this.currentType = type
      // 发射一个事件告诉爸爸儿子点了什么类型
      this.$emit('toggle-type', type)
    }
  },
  props: {
    // 获取父组件传递过来的任务数量
    num: {
      type: Number,
      default: 0,
    },
  },
};
</script>

<style>
</style>